<?php 
namespace app\common\upload;

use app\common\service\WeginService;
use EasyAdmin\upload\FileBase;
use EasyAdmin\upload\trigger\SaveDb;
use think\facade\Filesystem;

class LocalDriver extends FileBase
{

    public function save()
    {
        //把文件上传
        $this->completeFilePath = Filesystem::disk('public')->putFile('upload', $this->file);
        //或得上传后的url
        $this->completeFileUrl = config('filesystem.disks.public.url')   . str_replace(DIRECTORY_SEPARATOR, '/', $this->completeFilePath);
        SaveDb::trigger($this->tableName, [
            'uniacid'=> WeginService::getUniacid(),
            'upload_type'   => $this->uploadType,
            'original_name' => $this->file->getOriginalName(),
            'mime_type'     => $this->file->getOriginalMime(),
            'file_ext'      => strtolower($this->file->getOriginalExtension()),
            'url'           => $this->completeFileUrl,
            'create_time'   => time(),
        ]);
        return [
            'save' => true,
            'msg'  => '上传成功',
            'url'  => $this->completeFileUrl,
        ];
    }
}